home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <time.h>
-
- //Returns 1 if they intersect
- //returns 0 otherwise
- short LinesIntersect(unsigned long x1,unsigned long y1,
- unsigned long x2,unsigned long y2,
- unsigned long x3,unsigned long y3,
- unsigned long x4,unsigned long y4)
- {
- unsigned long d;
- d = (((y2-y1)*(x3-x4))-((y4-y3)*(x1-x2)));
- if (!d)
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
-
-
- short main()
- {
- long x1,x2,x3,x4,y1,y2,y3,y4;
- long index;
- clock_t st,et;
- long tt;
- float tps;
-
- printf("X1, Y1: ");
- scanf( "%ld %ld", &x1, &y1 );
- printf( "X2, Y2: " );
- scanf( "%ld %ld", &x2, &y2 );
- printf( "X3, Y3: " );
- scanf( "%ld %ld", &x3, &y3 );
- printf( "X4, Y4: " );
- scanf( "%ld %ld", &x4, &y4 );
-
- if (!LinesIntersect(x1,y1,x2,y2,x3,y3,x4,y4))
- {
- printf("Lines don't intersect\n");
- }
- else
- {
- printf("Lines intersect\n");// at %f,%f\n",intersectx,intersecty);
- }
- printf("Testing 500000 Times!\n");
- st=clock();
- for (index=0; index<500000; index++)
- {
- //LinesIntersect(x1,y1,x2,y2,x3,y3,x4,y4);
- unsigned long d;
- d = (((y2-y1)*(x3-x4))-((y4-y3)*(x1-x2)));
- if (!d)
- {
- //return 0;
- }
- else
- {
- //return 1;
- }
- }
- et=clock();
- tt=(long)et-(long)st;
- tps=((float)500000/(float)tt)*(float)CLK_TCK;
- printf("Total Test Per Second:%f\n",tps);
- return 0;
- }
-